package com.yang.controller;

import com.yang.domain.ResponseResult;
import com.yang.domain.User;
import com.yang.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
        // 登录
        Map<String, String> result = loginService.login(user);
        return ResponseResult.successResult("200", "登录成功", result);
    }

    @GetMapping("/user/logout")
    public ResponseResult logout() {
        loginService.logout();
        return ResponseResult.successResult();
    }

}
